package com.yxj02;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamDemo01 {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("D:\\Ccode\\jdata-structure\\ByteStream9\\fos.txt");

       /* //int read(byte[] b);从该输入流中最多读取b.length个字节的数据到一个字节数组
        byte[] b = new byte[5];
        //第一次读数据
        int len = fis.read(b);
        System.out.println(len);
        //System.out.println(new String(b));
        System.out.println(new String(b,0,len));

        //第二次读取数据
        len = fis.read(b);
        System.out.println(len);
        //System.out.println(new String(b));
        System.out.println(new String(b,0,len));

        //第三次读取
        len = fis.read(b);
        System.out.println(len);
        //String (byte[] bytes, int offset, int length)
        System.out.println(new String(b, 0, len));

        len = fis.read(b);
        System.out.println(len);*/
        /*
        * hello\r\n
        * world\r\n
        * 第一次：hello
        * 第二次：\r\nwor
        * */

        byte[] bytes = new byte[1024];
        int len;
        while((len = fis.read(bytes)) != -1) {
            System.out.println(new String(bytes,0,len));
        }

        fis.close();
    }
}
